package cn.zhonghuanzhiyuan.sprc.basicinfo.service;

import cn.hutool.core.util.IdUtil;
import cn.org.bachelor.iam.IamContext;
import cn.zhonghuanzhiyuan.sprc.basicinfo.dao.EntDutyMapper;
import cn.zhonghuanzhiyuan.sprc.basicinfo.domain.EntDuty;
import cn.zhonghuanzhiyuan.sprc.basicinfo.pojo.vo.QueryEntDutyVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * @param
 * @author 涛哥
 * @version 1.0
 * @ClassName:Name
 * @description:TODO
 * @date 2024/1/23 15:28
 */
@Slf4j
@Service
public class EntDutyService {

    @Autowired
    private EntDutyMapper  entDutyMapper;

    @Autowired
    private IamContext iamContext;
    /**
     * 查询企业值班信息列表
     * @param queryEntDutyVo
     * @return
     */
    public List<EntDuty> selectEntDutysList(QueryEntDutyVo queryEntDutyVo){
        return entDutyMapper.selectEntDutysList(queryEntDutyVo);
    }

    /**
     * 批量保存
     * @param duties
     */
    public void saveBatchDutys(List<EntDuty> duties){
        duties.stream().forEach(item -> saveEntDuty(item));

    }


    /**
     * 保存实体
     * @param entDuty
     */
    public void saveEntDuty(EntDuty entDuty) {
        String orgName =/* iamContext.getUser().getOrgName();*/ "蓝桥集团";
        String orgId = /*iamContext.getUser().getOrgId();*/ "8B0411";
        String userName =/*iamContext.getUser().getName();*/"蓝桥涛哥";
        Date addDate = new Date();
        entDuty.setId(IdUtil.simpleUUID());
        entDuty.setCreateTime(addDate);
        entDuty.setCreateUser(userName);
        entDuty.setOrgName(orgName);
        entDuty.setOrgId(orgId);
        //TODO 缺少园区编号
        entDutyMapper.insert(entDuty);
    }

    public void deleteBatchDutysByIds(String ids) {
        log.info("删除主键集合或者单个：{}", ids);
        if (StringUtils.isNotEmpty(ids)) {
            Arrays.asList(ids.split(",")).stream().forEach(id -> {
                Example example = new Example(EntDuty.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("id", id);
                entDutyMapper.delete(entDutyMapper.selectOneByExample(example));
            });
        }
    }

}












